package DP;

/**
 * @author 曹见朋
 * @create 2024-06-13-0:12
 */
public class Main279 {
    // TODO 279. 完全平方数
    public static int numSquares(int n) {
        int[] dp = new int[n + 1];
        int max = Integer.MAX_VALUE;
        for(int i = 0; i < dp.length; i++){
            dp[i] = max;
        }
        dp[0] = 0;
        for(int i = 1; i * i <= n; i++){
            for(int j = i * i; j <= n; j++){
                dp[j] = Math.min(dp[j], dp[j - i * i] + 1);
            }
        }
        return dp[n];
    }

    public static void main(String[] args) {
        int n = 12;
        int i = numSquares(n);
        System.out.println(i);
    }
}
